import java.rmi.*;

//this is the import for the line that
//avoids the command line "start rmiregistry 6666" in the console
import java.rmi.registry.LocateRegistry;

import java.util.Scanner;
import java.util.StringTokenizer;

public class RMIClient {

	public static void main(String args[]) {

		System.getProperties().put("java.security.policy", "policy.all");
		System.setSecurityManager(new RMISecurityManager());

		try {

			//Hello h = (Hello) Naming.lookup("hello");
                        //this avoids the command line "start rmiregistry 6666" in the console
                        //pay attention to the name you LOOKUP for (the same as in naming.rebind...)
                        RMI r = (RMI) LocateRegistry.getRegistry(7007).lookup("idea");

			String a = r.sayHello();
			System.out.println(a);
			r.remote_print("print do client para o servidor...");

                        //########## .5 CODE HERE ##########

                        Scanner sc = new Scanner(System.in);
                        String value = sc.nextLine();
                        double v = Double.parseDouble(value);
                        String n = sc.nextLine();
                        String d = sc.nextLine();
                        User u = new User();
                        //System.out.println("### int= " + i + " , double = " + d + " , string = " + s);

                        //Idea m = new Idea(i, d, s);
                        // Idea(value, name, description, user)
                        Idea m = new Idea(v, n, d, u);
                        
			//h.remote_print(m);
                        r.publish(m);

			Idea m1 = r.ping_pong(m, u);
			//System.out.println(m1);
                        System.out.println(m1.toString());
                        
			//m.change_text("Ola Boa Noite");
			//System.out.println(m);

		} catch (Exception e) {
			System.out.println("Exception in main: " + e);
		}

	}

}
